package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
      @NamedQuery(name = "findAllRepositorys", query = "select myRepository from Repository myRepository"),
      @NamedQuery(name = "findRepositoryByCreatedDate", query = "select myRepository from Repository myRepository where myRepository.createdDate = ?1"),
      @NamedQuery(name = "findRepositoryByDescription", query = "select myRepository from Repository myRepository where myRepository.description = ?1"),
      @NamedQuery(name = "findRepositoryById", query = "select myRepository from Repository myRepository where myRepository.id = ?1"),
      @NamedQuery(name = "findRepositoryByName", query = "select myRepository from Repository myRepository where myRepository.name = ?1"),
      @NamedQuery(name = "findRepositoryByNameContaining", query = "select myRepository from Repository myRepository where myRepository.name like ?1"),
      @NamedQuery(name = "findRepositoryByPrimaryKey", query = "select myRepository from Repository myRepository where myRepository.id = ?1"),
      @NamedQuery(name = "findRepositoryByStatus", query = "select myRepository from Repository myRepository where myRepository.status = ?1"),
      @NamedQuery(name = "findRepositoryByStatusContaining", query = "select myRepository from Repository myRepository where myRepository.status like ?1"),
      @NamedQuery(name = "findRepositoryByUpdatedDate", query = "select myRepository from Repository myRepository where myRepository.updatedDate = ?1") })
@Table(catalog = "sow", name = "repository")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "Repository")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class Repository implements Serializable {
   private static final long serialVersionUID = 1L;

   /**
	 */

   @Column(name = "ID", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @XmlElement
   Integer id;
   /**
	 */

   @Column(name = "NAME", length = 50, nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String name;
   /**
	 */

   @Column(name = "DESCRIPTION", columnDefinition = "TEXT")
   @Basic(fetch = FetchType.EAGER)
   @Lob
   @XmlElement
   String description;
   /**
	 */
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "CREATED_DATE")
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Calendar createdDate;
   /**
	 */
   @Temporal(TemporalType.TIMESTAMP)
   @Column(name = "UPDATED_DATE")
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   Calendar updatedDate;
   /**
	 */

   @Column(name = "STATUS", length = 3)
   @Basic(fetch = FetchType.EAGER)
   @XmlElement
   String status;

   /**
	 */
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
   @XmlTransient
   User userByCreatedBy;
   /**
	 */
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumns({ @JoinColumn(name = "CLIENT_ID", referencedColumnName = "ID") })
   @XmlTransient
   Client client;
   /**
	 */
   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumns({ @JoinColumn(name = "UPDATED_BY", referencedColumnName = "ID") })
   @XmlTransient
   User userByUpdatedBy;
   /**
	 */
   // @OneToMany(mappedBy = "repository", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
   // @XmlElement(name = "", namespace = "")
   // java.util.Set<edu.hcmus.sow.domain.Folder> folders;

   @Column(name = "CLIENT_ID", updatable = false, insertable = false)
   private Integer clientID;

   public Integer getClientID() {
      return clientID;
   }

   public void setClientID(Integer clientID) {
      this.clientID = clientID;
   }

   /**
	 */
   public void setId(Integer id) {
      this.id = id;
   }

   /**
	 */
   public Integer getId() {
      return this.id;
   }

   /**
	 */
   public void setName(String name) {
      this.name = name;
   }

   /**
	 */
   public String getName() {
      return this.name;
   }

   /**
	 */
   public void setDescription(String description) {
      this.description = description;
   }

   /**
	 */
   public String getDescription() {
      return this.description;
   }

   /**
	 */
   public void setCreatedDate(Calendar createdDate) {
      this.createdDate = createdDate;
   }

   /**
	 */
   public Calendar getCreatedDate() {
      return this.createdDate;
   }

   /**
	 */
   public void setUpdatedDate(Calendar updatedDate) {
      this.updatedDate = updatedDate;
   }

   /**
	 */
   public Calendar getUpdatedDate() {
      return this.updatedDate;
   }

   /**
	 */
   public void setStatus(String status) {
      this.status = status;
   }

   /**
	 */
   public String getStatus() {
      return this.status;
   }

   /**
	 */
   public void setUserByCreatedBy(User userByCreatedBy) {
      this.userByCreatedBy = userByCreatedBy;
   }

   /**
	 */
   @JsonIgnore
   public User getUserByCreatedBy() {
      return userByCreatedBy;
   }

   /**
	 */
   public void setClient(Client client) {
      this.client = client;
   }

   /**
	 */
   @JsonIgnore
   public Client getClient() {
      return client;
   }

   /**
	 */
   public void setUserByUpdatedBy(User userByUpdatedBy) {
      this.userByUpdatedBy = userByUpdatedBy;
   }

   /**
	 */
   @JsonIgnore
   public User getUserByUpdatedBy() {
      return userByUpdatedBy;
   }

   /**
	 */
   // public void setFolders(Set<Folder> folders) {
   // this.folders = folders;
   // }

   /**
	 */
   // @JsonIgnore
   // public Set<Folder> getFolders() {
   // if (folders == null) {
   // folders = new java.util.LinkedHashSet<edu.hcmus.sow.domain.Folder>();
   // }
   // return folders;
   // }

   /**
	 */
   public Repository() {
   }

   /**
    * Copies the contents of the specified bean into this bean.
    * 
    */
   public void copy(Repository that) {
      setId(that.getId());
      setName(that.getName());
      setDescription(that.getDescription());
      setCreatedDate(that.getCreatedDate());
      setUpdatedDate(that.getUpdatedDate());
      setStatus(that.getStatus());
      setUserByCreatedBy(that.getUserByCreatedBy());
      setClient(that.getClient());
      setUserByUpdatedBy(that.getUserByUpdatedBy());
      // setFolders(new java.util.LinkedHashSet<edu.hcmus.sow.domain.Folder>(that.getFolders()));
   }

   /**
    * Returns a textual representation of a bean.
    * 
    */
   public String toString() {

      StringBuilder buffer = new StringBuilder();

      buffer.append("id=[").append(id).append("] ");
      buffer.append("name=[").append(name).append("] ");
      buffer.append("description=[").append(description).append("] ");
      buffer.append("createdDate=[").append(createdDate).append("] ");
      buffer.append("updatedDate=[").append(updatedDate).append("] ");
      buffer.append("status=[").append(status).append("] ");

      return buffer.toString();
   }

   /**
	 */
   @Override
   public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
      return result;
   }

   /**
	 */
   public boolean equals(Object obj) {
      if (obj == this)
         return true;
      if (!(obj instanceof Repository))
         return false;
      Repository equalCheck = (Repository) obj;
      if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
         return false;
      if (id != null && !id.equals(equalCheck.id))
         return false;
      return true;
   }
}
